package com.spider.ask120.service;

import org.jdiy.core.Args;
import org.jdiy.core.Ls;
import org.jdiy.core.Rs;
/**
 * 频道对应最新文章信息表
 * @author Shan
 *
 */
public class ChannelArticleInfoService extends BaseService{
	/**
	 * 根据channel id查找channel存储文章信息
	 * @param channel_id
	 * @return
	 */
	public static Rs getInfoByChId(Integer channel_id){
		Rs info = dao.rs(new Args("channel_article_info","channel_id="+channel_id));
		return info;
	}
	/**
	 * 保存频道文章信息
	 * @param ca
	 */
	public static void save(Rs ca){
		dao.save(ca);
	}
	/**
	 * 更新文章最新id到channel_article_info表
	 */
	public static void updateChannelArticleId(){
		Ls channel = dao.ls(new Args("channel"));
		if (channel.getItems().length > 0) {
			for (Rs ch : channel.getItems()) {
				Rs art = ArticleService.getArticlesByChannelId(ch.get("id"));
				String str_id = art.get("str_id");
				Rs ca = new Rs("channel_article_info");
				ca.set("article_str_id", str_id);
				ca.set("channel_id", art.get("str_id"));
				dao.save(ca);
			}
		}
	}
	
	public static void main(String[] args) {
		Rs info = getInfoByChId(1);
		//System.out.println(info.getInt("article_str_id"));
	}
}
